#ifndef _MAIN_H_
#define _MAIN_H_

#include <time.h>

#define MAX_AMOUNT 10

// 写入文件后每行的字符数（含 '\n' ）
#define LEN_CFG_LINE 70
#define LEN_PORT_LINE 58
#define LEN_PROTOCOL_LINE 35
#define LEN_NETCARD_LINE 34

#define MAX_FILE_PATH_LEN 50
#define MAX_PROTOCOL_NAME_LEN 7
#define MAX_NETCARD_NAME_LEN 6

#define NUM_PROTOCOL 5
#define NUM_NETCARD 5

typedef unsigned int u32;
typedef struct pkg
{
    u32 srcIP;
    u32 dstIP;
    unsigned int srcPort : 16;
    unsigned int dstPort : 16;
    unsigned int protocol : 8;
    unsigned int netcard : 8;
    time_t timestamp;
} Package;

extern char* cfgname;
extern char* portcfgname;
extern char* protocolcfgname;
extern char* netcardcfgname;
extern char* tmpname;
extern time_t TTL;
extern int totalIPLines;
extern int totalPtLines;
extern char* protocol[NUM_PROTOCOL];
extern char* netcard[NUM_NETCARD];


// 掩码，保留一个数中的某8位
// #define mask8(x, n) ((x) & (0x000000FF << ((n) * 8)))
inline u32 mask8(u32 IP, int n)
{
    return IP & (0x000000FF << (n * 8));
}

// IP 格式
#define IPformat "%3d.%3d.%3d.%3d"
// 格式化 IP 地址，用于向用户展示
#define format_IP(IP) mask8((IP), 3) >> 24, mask8((IP), 2) >> 16, \
mask8((IP), 1) >> 8, mask8((IP), 0)

#endif